package com.lijie.bs_recruit.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lijie.bs_recruit.model.Education;
import com.lijie.bs_recruit.service.EducationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李杰
 * @since 2021-03-16
 */
@RestController
@RequestMapping("/bs_recruit/education")
public class EducationController {
    @Autowired
    EducationService educationService;

    @RequestMapping("/addEducation")
    public String addEducation(@RequestBody Education education){
        String result="";
        boolean save = educationService.save(education);
        if(save){
            result="succ";
        }else{
            result="error";
        }
        return result;
    }
    @RequestMapping("/updateEducations")
    public String updateEducation(@RequestBody List<Education> educations){
        String result="succ";
        QueryWrapper<Education> deletewrapper=new QueryWrapper<>();
        deletewrapper.eq("userId", educations.get(0).getUserId());
        educationService.remove(deletewrapper);
        for(Education e:educations){
            boolean update = educationService.save(e);
            if(!update){
                result="error";
                break;
            }
        }
        return result;
    }
}

